from django.db import models


# Create your models here.
from webcases.config import ORDER_CHOICES, LOCATE_CHOICES, BROWSER_CHOICES


class WebTestingProject(models.Model):
    """WEB测试项目类模型定义"""
    project_name = models.CharField(max_length=20, verbose_name='项目名称')
    project_desc = models.CharField(max_length=200, null=True, blank=True, verbose_name='项目描述')
    creator = models.CharField(max_length=20, verbose_name='创建人')
    create_date = models.DateField(verbose_name='创建时间', null=True)
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'tb_web_projects'
        verbose_name = 'WEB测试项目'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.project_name


class WebTestingCase(models.Model):
    """WEB测试项目类模型定义"""
    case_name = models.CharField(max_length=20, verbose_name='用例名称')
    case_desc = models.CharField(max_length=100, null=True, blank=True, verbose_name='用例描述')
    project_name = models.ForeignKey(WebTestingProject, on_delete=models.SET_NULL, null=True, blank=True, verbose_name='所属项目')
    browser = models.CharField(choices=BROWSER_CHOICES, max_length=10, verbose_name='浏览器')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'tb_web_cases'
        verbose_name = 'WEB测试用例'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.case_name


class WebTestingCaseSteps(models.Model):
    """WEB测试步骤类模型定义"""
    step_sequence = models.SmallIntegerField(verbose_name='步骤顺序')
    step_name = models.CharField(max_length=20, verbose_name='测试步骤')
    step_order = models.CharField(choices=ORDER_CHOICES, max_length=40, default='', verbose_name='步骤命令')
    locate_by = models.CharField(choices=LOCATE_CHOICES, max_length=20, default='xpath', verbose_name='定位方式')
    locate_pattern = models.CharField(max_length=100, null=True, blank=True, verbose_name='页面元素、具体值')
    value = models.CharField(max_length=100, null=True, blank=True, verbose_name='数据项')
    case_name = models.ForeignKey(WebTestingCase, on_delete=models.CASCADE, verbose_name='测试用例')

    class Meta:
        db_table = 'tb_web_cases_steps'
        verbose_name = 'WEB测试步骤'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.step_name
